package com.next.aappublicapp;

import java.util.List;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;

import com.google.analytics.tracking.android.EasyTracker;
import com.next.aap.client.BaseItem;
import com.next.aap.client.NewsItem;
import com.next.aappublicapp.adapters.SectionsPagerAdapter;
import com.next.aappublicapp.fragments.NewsFragment;

public class PagerViewActivity extends BaseFragmentActivty {

	/**
	 * The {@link android.support.v4.view.PagerAdapter} that will provide
	 * fragments for each of the sections. We use a
	 * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
	 * will keep every loaded fragment in memory. If this becomes too memory
	 * intensive, it may be best to switch to a
	 * {@link android.support.v4.app.FragmentStatePagerAdapter}.
	 */
	SectionsPagerAdapter mSectionsPagerAdapter;
	
	public static final String ARGS_ITEM_LIST = "ARGS_ITEM_LIST";
	public static final String ARGS_ITEM_POSITION = "ARGS_ITEM_POSITION";
	public static final String ARGS_BUNDLE = "ARGS_BUNDLE";

	/**
	 * The {@link ViewPager} that will host the section contents.
	 */
	ViewPager mViewPager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_show_news);
		EasyTracker.getTracker().sendView("News View");
		//Get the List of Items
		Bundle bundle = getIntent().getBundleExtra(ARGS_BUNDLE);
		List<? extends BaseItem> itemList = (List<? extends BaseItem>)bundle.getSerializable(ARGS_ITEM_LIST);        
		int currentPosition =  bundle.getInt(ARGS_ITEM_POSITION);
		
		// Create the adapter that will return a fragment for each of the three
		// primary sections of the app.
		mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), itemList);
		
		// Set up the ViewPager with the sections adapter.
		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(mSectionsPagerAdapter);
		mViewPager.setCurrentItem(currentPosition);
	}

	
	/*
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.show_news, menu);
		return true;
	}
	*/

}
